<template>
  <div class="navbar-container">
    <div class="navbar">
      <div class="navbar__left">
        <img src="https://picsum.photos/100/100" alt="none" />
      </div>
      <div class="navbar__middle">
        <ul>
          <li
            v-for="(item, index) in list"
            :key="index"
            @click="linkHandle(item)"
          >
            <a>{{ item.label }}</a>
          </li>
        </ul>
      </div>
      <div class="navbar__right">
        <button>免费试用</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      default: function () {
        return [{
          label: '主页',
          path: '/home'
        }, {
          label: '产品',
          path: '/product'
        }, {
          label: '价格',
          path: '/price'
        }, {
          label: '关于',
          path: '/about'
        }, {
          label: '博客',
          path: '/blog'
        }, {
          label: '联系',
          path: '/contact'
        }]
      }
    }
  },
  methods: {
    linkHandle (item) {
      const curPath = this.$route.fullPath
      if (curPath.includes(item.path)) return
      this.$router.push(item.path)
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar-container {
  .navbar {
    display: flex;
    align-items: center;
    height: 72px;
    &__left,
    &__right {
      flex: 0 0 20%;
    }
    &__left {
      text-align: right;
      img {
        width: 50px;
        height: 50px;
      }
    }
    &__middle {
      flex: 1;
      ul {
        display: flex;
        justify-content: flex-end;
        li {
          min-width: 100px;
          cursor: pointer;
          a {
            &:hover {
              color: #6b7cff;
            }
          }
        }
      }
    }
  }
}
</style>
